import os

import requests
import time
def get_shuruxinxi(url_ip,person_id,bianhao,cookie,Yyks,yvyuehaobie,Yyrq,qyys,ysmc,ysdm,has_yyys):
    url = f'{url_ip}/cis/psiregregisters/effectivepatient/{person_id}/{bianhao}?t={str(time.time()).replace(".","")[0:13]}'
    url2 = f'{url_ip}/cis/psiregpatients/getorgcode/{person_id}?t={str(time.time()).replace(".","")[0:13]}'
    headers = {
        "accept": "application/json",
        "cookie": f"JSESSIONID={cookie}",
    }
    res = requests.get(url, headers=headers).json()

    # 获取姓名
    PatientName = res["registerinfo"]["pattName"]
    # 随访
    Purpose = "随访"
    # sfqh
    Sfqh = "0"
    # 随访医生

    Sqys = ysmc

    # Yxq有效期
    Yxq = 1
    # 预约号别--应该写死普通门诊
    Yyhb = yvyuehaobie
    # 预约号别id--应该写死普通门诊id--908
    YyhbId = res["registerinfo"]["registerTypeNew"]
    # 预约科室
    Yyks = Yyks
    # 预约科室id
    YyksId = str(res["registerinfo"]["departmentId"])




    # 预约日期
    # # 原始日期提取并月份加1（自动处理月末情况）
    # update_date_str = res["registerinfo"]["updateDate"].split()[0]
    # date_obj = datetime.strptime(update_date_str, "%Y-%m-%d")
    # # 使用 relativedelta 实现月份加1，自动处理月末等边界情况
    # new_date = date_obj + relativedelta(months=1)
    # Yyrq = new_date.strftime("%Y-%m-%d")


    Yyrq = Yyrq.replace("/", "-")
    # 预约时间
    Yysj = "8-00~9-00"

    # 预约医生
    if has_yyys=="是":
        Yyys =ysmc
    else:
        Yyys = ""


    # 签约医生
    if len(qyys)<2:
        qyys = ""
    Jtys = qyys

    # 预约医生id
    YyysId = str(ysdm)
    # 电话号码
    dwsPhoneNumber = res["registerinfo"]["phoneNumber"]
    # 转诊预约来源-列表对应（）
    referralBookingSource = 0
    res2 = requests.get(url2, headers=headers).json()
    Brithday = res2["birthday"]
    PatientSex = res2["patientSex"]
    if PatientSex == 1:
        PatientSex = "男性"
    elif PatientSex == 2:
        PatientSex = "女性"

    Brbm = res2["identityCode"]

    all_post_info = {
        "Birthday": Brithday,
        "Brbm": Brbm,
        "Jtys": Jtys,
        "PatientName": PatientName,
        "PatientSex": PatientSex,
        "Purpose": Purpose,
        "Sfqh": Sfqh,
        "Sqys": Sqys,
        "Yxq": Yxq,
        "Yyhb": Yyhb,
        "Yyhbid": YyhbId,
        "Yyks": Yyks,
        "Yyksid": YyksId,
        "Yyrq": Yyrq,
        "Yysj": Yysj,
        "Yyys": Yyys,
        "Yyysid": YyysId,
        "dwsPhoneNumber": dwsPhoneNumber,
        "referralBookingSource": referralBookingSource,
    }
    print(all_post_info)
    return all_post_info

if __name__ == '__main__':
    url_ip = "http://10.216.11.12:8089/"
    person_id = "0007091911240026"
    bianhao = "00070925072800030"
    cookie = "D81BCCC10571FC81EB61518E0EB26173"
    Yyks = "中医科"
    yvyuehaobie = "普通门诊"
    Yyrq = "2025-07-30"
    ysmc = "牛飞"
    xianchengshu = 1
    get_shuruxinxi(url_ip, person_id, bianhao, cookie, Yyks,yvyuehaobie,Yyrq,ysmc,1)





